/*
 * MiniPOVEditor
 * by Andy Isaacson 10/5/2008
 * Written on a Sunday morning
 * 
 * For the MiniPOV kit - http://ladyada.net/make/minipov3/index.html
 */

import java.awt.Dimension;
import java.util.ArrayList;

import javax.swing.JPanel;


public class Column extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5141962304799138436L;
	
	private ArrayList<Cell> cells;
	private int cellSize;
	private int cellSpacing;
	private int numColumnsShown = 20; //Kind of a hack

	
	public Column(MiniPOVEditor mainParent, int cellSize, int cellSpacing) {
		super(null);
		
		this.cellSize = cellSize;
		this.cellSpacing = cellSpacing;
		
		cells = new ArrayList<Cell>();
		
		for (int i=0; i<8; i++) {
			Cell curCell = new Cell(mainParent);
			this.add(curCell);
			curCell.setSize(new Dimension(this.cellSize, this.cellSize));
			curCell.setLocation(0, i*(this.cellSize + this.cellSpacing));
			cells.add(curCell);
			
			this.setSize(cellSize, 8*this.cellSize + 7*this.cellSpacing);
		}
	}

	public String getColumnImgCode() {
		StringBuilder sb = new StringBuilder();
		
		sb.append("B8(");
		
		for (int i=7; i>=0; i--) {
			Cell c = cells.get(i);
			sb.append( c.isOn() ? "1" : "0");
		}
		
		sb.append("),");
		return sb.toString();
	}
	
	public void clear() {
		for (Cell c : cells) {
			c.setOn(false);
		}
	}
	
	public ArrayList<Cell> getCells() {return cells;}
	
	public void setTo(Column c) {
		ArrayList<Cell> ccells = c.getCells();
		for (int i=0; i<8; i++) {
			cells.get(i).setOn(ccells.get(i).isOn());
		}
	}

	public int getNumColumnsShown() {
		return numColumnsShown;
	}

	public void setNumColumnsShown(int numColumnsShown) {
		this.numColumnsShown = numColumnsShown;
	}
}
